package com.example.app.createmodel.singlemodel;

/**
 * 饿汉模式
 */
public final class Person4 {
	private String name;
	//保证内存可见性，防止编译器过度优化(指令重排序)
	private static volatile Person4 person=null;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	//私有化构造方法
	private Person4() {
	}
	
	//双重加锁实现
	public static Person4 getPerson() {
		if(person == null) {
			synchronized (Person4.class) {
				if(person == null) {
					person = new Person4();
				}
			}
		}
		return person;
	}
}
